import { request } from '@/utils/request'
import type { ApiResponse } from '@/utils/request'

/**
 * 学院查询参数
 */
export interface CollegeQuery {
  schoolId?: number
  collegeCode?: string
  collegeName?: string
  director?: string
  isActive?: boolean
  pageNum: number
  pageSize: number
}

/**
 * 学院表单数据
 */
export interface CollegeForm {
  id?: number
  schoolId: number
  schoolName?: string
  collegeCode: string
  collegeName: string
  establishedDate?: string
  director?: string
  contactPhone?: string
  email?: string
  address?: string
  description?: string
  isActive?: boolean
}

/**
 * 学院详情
 */
export interface CollegeInfo extends CollegeForm {
  createdTime?: string
  updatedTime?: string
  createdBy?: number
  updatedBy?: number
}

/**
 * 学院分页结果接口
 */
export interface CollegePageResult {
  records: CollegeInfo[]
  total: number
  size: number
  current: number
  pages: number
}

/**
 * 获取学院列表
 * @param query 查询参数
 * @returns 分页结果
 */
export function listCollege(query: CollegeQuery) {
  return request.post<ApiResponse<CollegePageResult>>('/api/school/college/list', query)
}

/**
 * 获取学院详情
 * @param id 学院ID
 * @returns 学院详情
 */
export function getCollege(id: number) {
  return request.get<ApiResponse<CollegeInfo>>(`/api/school/college/${id}`)
}

/**
 * 新增学院
 * @param data 学院数据
 * @returns 新增结果
 */
export function addCollege(data: CollegeForm) {
  return request.post<ApiResponse<boolean>>('/api/school/college', data)
}

/**
 * 修改学院
 * @param data 学院数据
 * @returns 修改结果
 */
export function updateCollege(data: CollegeForm) {
  return request.put<ApiResponse<boolean>>('/api/school/college', data)
}

/**
 * 删除学院
 * @param id 学院ID
 * @returns 删除结果
 */
export function deleteCollege(id: number) {
  return request.delete<ApiResponse<boolean>>(`/api/school/college/${id}`)
}

/**
 * 批量删除学院
 * @param ids 学院ID数组
 * @returns 批量删除结果
 */
export function batchDeleteCollege(ids: number[]) {
  return request.delete<ApiResponse<boolean>>('/api/school/college/batch', ids)
} 